package com.jjr.action;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import tool.ClientTool;
import tool.TimeTool;

import com.base.bean.*;
import com.base.service.*;
import com.jjr.bean.JClientDetail;
import com.jjr.bean.JsonResult;
import com.jjr.service.JingJiRenService;

/**
 * 功能： 验证电话号码（格式 重复性）
 */
public class JClientAction extends BaseAction {
	private Integer id;
	private String name, comName, memo;
	private String area, city, province;
	private String areaId,cityId,provinceId;
	private String wjjpp, zzjpp, gmsbType;
	private Integer gmTimeType;
	private String phones;
	private String phoneIds;

	private JingJiRenService js;

	public JClientAction() {
		js = JingJiRenService.getInstance();
	}

	public static void main(String[] args){
		JClientAction a = new JClientAction();
		a.id=0;
		a.name="jack";
		a.phones="15982079518";
		a.phoneIds = "0";
		a.area="成华区2";
		a.city="成都2";
		a.province="四川2";
		a.mergeClient();
		System.out.println(a.result.getTip());
		
		
	}
	
	public String mergeClient() {
		String[] _phones = this.phones.split(",");
		String[] _phoneIds = this.phoneIds.split(",");
		
//		正式部署删除这句
//		this.openId="aaa";
		
		JingJiRenService js = JingJiRenService.getInstance();

		this.openId = (this.openId == null ? "" : this.openId);
		
		if(this.openId.equals("")){
			this.result.setTip("未识别到登录用户，请重新登录");
			this.result.setState(-1);
			return SUCCESS;
		}
		
		
		this.id = (this.id == null ? 0 : this.id);
		this.name = (this.name == null ? "" : this.name.replaceAll("\\s*", ""));
		this.comName = (this.comName == null ? "" : this.comName.replaceAll(
				"\\s*", ""));
		this.memo = (this.memo == null ? "" : this.memo.replaceAll("\\s*", ""));
		this.area = (this.area == null ? "" : this.area);
		this.city = (this.city == null ? "" : this.city);
		this.province = (this.province == null ? "" : this.province);
		
		this.areaId = (this.areaId == null ? "" : this.areaId);
		this.cityId = (this.cityId == null ? "" : this.cityId);
		this.provinceId = (this.provinceId == null ? "" : this.provinceId);
		

		this.wjjpp = (this.wjjpp == null ? "" : this.wjjpp);
		this.zzjpp = (this.zzjpp == null ? "" : this.zzjpp);
		this.gmsbType = (this.gmsbType == null ? "" : this.gmsbType);
		this.gmTimeType = (this.gmTimeType == null ? 0 : this.gmTimeType);

		JClientDetail jcd = new JClientDetail();
		JClient jc = new JClient();
		jc.setId(this.id);
		jc.setArea(area);
		jc.setCity(city);
		jc.setProvince(province);
		jc.setComName(comName);
		jc.setCreated(TimeTool.getCurrentTime());
		
		try{
		jc.setCreator(js.getUidByOpenId(this.openId));
		}catch(Exception e){
			e.printStackTrace();
			jc.setCreator(0);
		}
		jc.setGmsbType(gmsbType);
		jc.setGmTimeType(gmTimeType);
		jc.setMemo(memo);
		jc.setName(name);
		jc.setWjjpp(wjjpp);
		jc.setZzjpp(zzjpp);
		jcd.setjClient(jc);

		Timestamp now = TimeTool.getCurrentTime();
		List<JClientPhone> jps = new ArrayList<JClientPhone>();

		for (int i = 0; i < _phones.length; i++) {
			Integer _id = (new Integer(_phoneIds[i])==null?0: new Integer(_phoneIds[i]));
			JClientPhone jcp = new JClientPhone();
			jcp.setId(_id);
			jcp.setPhone(_phones[i]);
			jps.add(jcp);

		}
		jcd.setJpList(jps);
		this.result = js.mergeJClient(jcd);
		return SUCCESS;
	}
	

	@Override
	public String execute() {

		return SUCCESS;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getComName() {
		return comName;
	}

	public void setComName(String comName) {
		this.comName = comName;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getWjjpp() {
		return wjjpp;
	}

	public void setWjjpp(String wjjpp) {
		this.wjjpp = wjjpp;
	}

	public String getZzjpp() {
		return zzjpp;
	}

	public void setZzjpp(String zzjpp) {
		this.zzjpp = zzjpp;
	}

	public String getGmsbType() {
		return gmsbType;
	}

	public void setGmsbType(String gmsbType) {
		this.gmsbType = gmsbType;
	}

	public Integer getGmTimeType() {
		return gmTimeType;
	}

	public void setGmTimeType(Integer gmTimeType) {
		this.gmTimeType = gmTimeType;
	}

	public JingJiRenService getJs() {
		return js;
	}

	public void setJs(JingJiRenService js) {
		this.js = js;
	}

	public String getPhones() {
		return phones;
	}

	public void setPhones(String phones) {
		this.phones = phones;
	}

	public String getPhoneIds() {
		return phoneIds;
	}

	public void setPhoneIds(String phoneIds) {
		this.phoneIds = phoneIds;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	public String getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}

	



}
